package com.jk.lzy.service.Impl;

import com.jk.lzy.dao.EmpDao;
import com.jk.lzy.model.EmpBean;
import com.jk.lzy.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: 梁展艺
 * @Description: 业务 层
 * @Date: 2021/5/16 18:43
 * @param null
 * @Return:
 **/
@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpDao empDao;

    @Override
    public HashMap<String, Object> findEmp(EmpBean emp) {
        Integer start = (emp.getPage() -1) * emp.getRows();
        Integer count = empDao.findEmpCount(emp);
        List<EmpBean> list = empDao.findEmp(start,emp.getRows(),emp);
        HashMap<String, Object> map = new HashMap<>();
        map.put("total",count);
        map.put("rows",list);
        return map;
    }
    // 新增
    @Override
    public void insertEmp(EmpBean emp) {
        if (emp.getId() == null){
            empDao.insertEmp(emp); // 新增
        }else {
            empDao.updateEmp(emp); // 修改
        }
    }
    // 删除
    @Override
    public void deleteEmp(Integer id) {
        empDao.deleteEmp(id);
    }
    // 修改 回显
    @Override
    public EmpBean updateEmpFindId(Integer id) {
        return empDao.updateEmpFindId(id);
    }
}
